package com.erp.app.admin.companyMenu.web;

//JRE Classes
import java.util.ArrayList;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.erp.app.admin.systemMenu.beans.SystemMenuGroupVO;
import com.erp.app.common.ProjectConstants;
import com.erp.framework.controller.form.SimpleMaintStyleForm;
import com.erp.framework.util.CommonUtil;

public class CompanyMenuMaintenanceForm extends SimpleMaintStyleForm {

    // T_COMPANY_MENU_GROUP
    private String companyCode;
    private String groupId;
    private String menuId;
    private String viewLevel;
    private String createLevel;
    private String updateLevel;
    private String deleteLevel;
    private String createDate;
    private String createUser;
    private String updateDate;
    private String updateUser;
    private String roleGroupId;
    private String existInd;

    // T_COMPANY_MENU_OBJECT
    private String[] objectId;
    private String[] visibleLevel;
    private String[] enableLevel;
    private String[] objectExistInd;

    private SystemMenuGroupVO menuGroupVO;

    /*
     * Get/Set for Property companyCode
     */
    public String getCompanyCode() {
        return companyCode;
    }

    public void setCompanyCode(String companyCode) {
        this.companyCode = companyCode;
    }

    /*
     * Get/Set for Property groupId
     */
    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    /*
     * Get/Set for Property menuId
     */
    public String getMenuId() {
        return menuId;
    }

    public void setMenuId(String menuId) {
        this.menuId = menuId;
    }

    /*
     * Get/Set for Property viewLevel
     */
    public String getViewLevel() {
        return viewLevel;
    }

    public void setViewLevel(String viewLevel) {
        this.viewLevel = viewLevel;
    }

    /*
     * Get/Set for Property createLevel
     */
    public String getCreateLevel() {
        return createLevel;
    }

    public void setCreateLevel(String createLevel) {
        this.createLevel = createLevel;
    }

    /*
     * Get/Set for Property deleteLevel
     */
    public String getDeleteLevel() {
        return deleteLevel;
    }

    public void setDeleteLevel(String deleteLevel) {
        this.deleteLevel = deleteLevel;
    }

    /*
     * Get/Set for Property updateLevel
     */
    public String getUpdateLevel() {
        return updateLevel;
    }

    public void setUpdateLevel(String updateLevel) {
        this.updateLevel = updateLevel;
    }

    /*
     * Get/Set for Property createDate
     */
    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    /*
     * Get/Set for Property createUser
     */
    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    /*
     * Get/Set for Property updateDate
     */
    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }

    /*
     * Get/Set for Property updateUser
     */
    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    /*
     * Get/Set for Property objectId[]
     */
    public String[] getObjectId() {
        return objectId;
    }

    public void setObjectId(String[] objectId) {
        this.objectId = objectId;
    }

    /*
     * Get/Set for Property visibleLevel[]
     */
    public String[] getVisibleLevel() {
        return visibleLevel;
    }

    public void setVisibleLevel(String[] visibleLevel) {
        this.visibleLevel = visibleLevel;
    }

    /*
     * Get/Set for Property enableLevel[]
     */
    public String[] getEnableLevel() {
        return enableLevel;
    }

    public void setEnableLevel(String[] enableLevel) {
        this.enableLevel = enableLevel;
    }

    /*
     * Get/Set for Property menuGroupVO
     */
    public SystemMenuGroupVO getMenuGroupVO() {
        return menuGroupVO;
    }

    public void setMenuGroupVO(SystemMenuGroupVO menuGroupVO) {
        this.menuGroupVO = menuGroupVO;
    }

    public void otherReset(ActionMapping mapping, HttpServletRequest request) {
        String emptyString = "";
    }

    public void otherValidate(ActionErrors errors) {
        
        // remark header
        if (CommonUtil.isEmpty(this.menuId)) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.field.blank", "Menu ID"));
            return;
        } else {
            menuId = menuId.trim().toUpperCase();
        }

        ArrayList checkList = new ArrayList();

        // menu items
        ArrayList rows = getMultiRows(0);
        Iterator iterator = rows.iterator();
        while (iterator.hasNext()) {
            CompanyMenuObjectRow row = (CompanyMenuObjectRow) iterator.next();

            if (row == null)
                continue;
            if (!CommonUtil.isEmpty(row.getIsDelete()))
                continue;

            String currentObjectId = CommonUtil.nullToString(row.getObjectId());

            if (CommonUtil.isEmpty(currentObjectId)) {
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.field.blank", "Menu Object ID"));
                return;
            } else {
                row.setObjectId(currentObjectId.trim().toUpperCase());
                row.setMenuId(menuId);
            }

            if (checkList.contains(row.getObjectId())) {
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.key.duplicate", row.getObjectId()));
                return;
            } else {
                checkList.add(row.getObjectId());
            }
        }

        checkList.clear();
        checkList = null;

        String[] tempIdArray = this.getObjectId();
        String tempStr = null;
        if (tempIdArray != null) {
            for (int i = 0; i < tempIdArray.length; i++) {
                tempStr = tempIdArray[i];
                if (tempStr != null) {
                    tempIdArray[i] = tempStr.trim().toUpperCase();
                }
            }
        }

    }

    public String getRoleGroupId() {

        return roleGroupId;
    }

    public void setRoleGroupId(String roleGroupId) {

        this.roleGroupId = roleGroupId;
    }

    public String getExistInd() {

        return existInd;
    }

    public void setExistInd(String existInd) {

        this.existInd = existInd;
    }

    public String[] getObjectExistInd() {

        return objectExistInd;
    }

    public void setObjectExistInd(String[] objectExistInd) {

        this.objectExistInd = objectExistInd;
    }
}
